<include file='Common:header'/>

<link rel="stylesheet" href="__PUBLIC__/resource/plugins/zTree/zTreeStyle/zTreeStyle.css">
<style type="text/css">
</style>

<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            权限设置
            <small>Role Access</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="{:U('Index/index')}"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li class="active">权限设置</li>
        </ol>
    </section>

    <!-- Main content -->
    <section class="content">

        <!-- START CUSTOM TABS -->
        <div class="row">
            <div class="col-xs-12">
                <!-- Custom Tabs -->
                <div class="nav-tabs-custom">

                    <ul class="nav nav-tabs">

                        <li class="active" data-toggle="tab"><a href="#tab_detail">权限设置</a></li>
                        <li><a href="{:U('Role/index')}">角色列表</a></li>
                        <li class="pull-right"></li>
                    </ul>

                    <div class="tab-content">

                        <div class="tab-pane active" id="tab_detail">


                            <div style="width:100%;">

                                <div class="wrap J_check_wrap">
                                    <div class="h_a">{$name} - 角色授权</div>
                                    <form class="accessForm" method="post">
                                        <div class="table_full">
                                            <ul id="treeDemo" class="ztree">
                                            </ul>
                                        </div>
                                        <div class="btn_wrap">
                                            <div class="btn_wrap_pd">
                                                <input type="hidden" name="rid" value="{$rid}" />
                                                <input type="hidden" name="menuid" value="" />
                                                <button type="submit" class="btn btn-primary">授权</button>
                                            </div>
                                        </div>
                                    </form>
                                </div>

                            </div>
                        </div><!-- /.tab-pane -->

                    </div><!-- /.tab-content -->


                </div><!-- nav-tabs-custom -->
            </div><!-- /.col -->

        </div> <!-- /.row -->
        <!-- END CUSTOM TABS -->

    </section><!-- /.content -->
</div><!-- /.content-wrapper -->

<script type="text/javascript">
    //配置
    var setting = {
        check: {
            enable: true,
            chkboxType:{ "Y" : "ps", "N" : "ps" }
        },
        data: {
            simpleData: {
                enable: true,
                idKey: "nid",
                pIdKey: "pid",
            }
        },
        callback: {
            beforeClick: function (treeId, treeNode) {
                if (treeNode.isParent) {
                    zTree.expandNode(treeNode);
                    return false;
                } else {
                    return true;
                }
            },
            onClick:function(event, treeId, treeNode){

            }
        }
    };
    //节点数据
    var zNodes ={$json|json_encode};
    //zTree对象
    var zTree = null;
    $(function(){
        $.fn.zTree.init($("#treeDemo"), setting, zNodes);
        zTree = $.fn.zTree.getZTreeObj("treeDemo");
        zTree.expandAll(true);
    });

    $('.accessForm button[type=submit]').bind('click', function (e) {
        e.preventDefault();
        var btn = $(this);
        var form = btn.parents('form.accessForm');

        //处理被选中的数据
        form.find('input[name="menuid"]').val("");
        var  nodes = zTree.getCheckedNodes(true);
        var menuid = "";
        $.each(nodes,function(i,value){
            if (menuid != "") {
                menuid += ",";
            }
            menuid += value.nid;
        });
        form.find('input[name="menuid"]').val(menuid);
        //btn.submit();

        doItem('{:U("edit")}', {menuid: menuid, rid: '{$rid}'});
    });
</script>

<include file='Common:footer'/>